Packet flow
Hyper-V Switch connections structure
The diagram below shows connections between a host and two containers with vRouter extension loaded to Hyper-V Switch. All interfaces (vhost, virtual, physical) are connected to the Hyper-V Switch and all packets are handled by vRouter.
Packet processing
-
Packets are sent from the host OS to vhost interface, from container to the virtual interface, or received on physical interface.
-
Packets are processed by NDIS and vRouter's
FilterSendNetBufferListsfunction is called. It receives a list ofNBLs(a list of lists of packets, see more here). -
If the switch is not running,
NdisFSendNetBufferListsCompletefunction is caled and all packets are dropped. -
NBLlist is split into two lists: one that will be processed by vRouter and second, that requires native forwarding and will be forwarded by Hyper-V Switch. -
Natively-forwarded
NBLsare passed to NDIS usingNdisFSendNetBufferListsfunction. -
NBLlist is split into separateNBLs. -
If there are no VIFs yet, packets are processed using simple switch logic without using of vRouter logic: they are sent to correct port using
NdisFSendNetBufferListsfunction. -
Every
NBLmay contain multiple packets (NBs). It is represented as aWIN_MULTI_PACKET- an NDIS-independent wrapper. The system independent dp-core code handles single packet at a time, soWIN_MULTI_PACKETis converted toPWIN_PACKET_LIST- a list ofWIN_PACKETstructures which are wrappera aroundNBLcontaining singleNB. For more information about wrappers, please see Windows structures abstraction. -
For every
WIN_PACKET, aVR_PACKET_WRAPPERstructure is allocated. It contains avr_packetstructure - a packet representation used in dp-core, which is linked in underlyingNBL. -
The dp-core code requires that all packet headers are in a continuous memory region. On Windows, each
NBcontains a list ofMDLswhich describes multiple memory regions. To avoid a situation when the headers are in different memory regions, new NBL containing continuous memory region is allocated and all data is copied there. -
The packet is sent to dp-core using
vif_rxfunction for selectedvif. -
After processing the packet by dp-core, the
win_if_txfunction is called. The checksums are recalculated or offloaded - depending on checksum type and offload capabilities of the hardware - and the packet if split if it is too large (it is segmented - for TCP packets, or fragmented - for non-TCP packets). After this process the resulting packets are represented asWIN_MULTI_PACKET. -
The destination port for the packets is selected basing on the
vif. The packet is passed to NDIS usingNdisFSendNetBufferListsfunction. -
After processing the packet by all layers of drivers, NDIS calls
FilterSendNetBufferListsCompletefunction. vRouter frees all allocated packets and completes packets allocated by upper-layer drivers.